

#include "WriteText.h"


WriteText::WriteText()
{
	//ObjectVector m_TextV;
	//m_TextObj TheTextObj(){};
}


void WriteText::DefineAll(float R, float G, float B, float A, std::string& TheText, Vec3f TheCord)
{
	TextColour(R,G,B,A);
	SetText(TheText);
	TextCord(TheCord);


}

void WriteText::AddToVector()
{
	
	//m_TextObj TheTextObj(){}(TheTextObj;
	//TheTextObj.R=
	TextObj TheTextObj;
	TheTextObj.R = m_colour.X;
	TheTextObj.G = m_colour.Y;
	TheTextObj.B = m_colour.Z;
	TheTextObj.A = m_alpha;
	TheTextObj.TheCord = m_cord;
	TheTextObj.TheText =m_text;
	ObjectVector.push_back(TheTextObj);
	

}

void WriteText::TextColour(float R, float G, float B, float A)
{
	m_colour.X = R;
	m_colour.Y = G;
	m_colour.Z = B;
	m_alpha = A;
}

//void TextColour(Vec3f& Colour);
void WriteText::TextColour(Vec3f Colour, float A)
{
	m_colour.X = Colour.X;
	m_colour.Y = Colour.Y;
	m_colour.Z = Colour.Z;
	m_alpha = A;

}
void WriteText::SetText(std::string& TheText)
{
	m_text = TheText;

}
void WriteText::TextCord(Vec3f TheCord)
{
	m_cord = TheCord;
}

void WriteText::DrawVec()
{
	unsigned int i=0;
	while (i<ObjectVector.size())
	{
		/*
		m_textObj Current;
		Current.A = ObjectVector[i].A;
		Current.B = ObjectVector[i].B;
		Current.G = ObjectVector[i].G;
		Current.R = ObjectVector[i].R;
		Current.TheCord = ObjectVector[i].TheCord;
		Current.TheText = ObjectVector[i].TheText;
		DefineAll(Current.R,Current.G,Current.B,Current.A,Current.TheText,Current.TheCord);
		//or
		*/
		//m_textObj = ObjectVector[i];
		DefineAll(ObjectVector[i].R,ObjectVector[i].G, ObjectVector[i].B, ObjectVector[i].A, 
					ObjectVector[i].TheText,ObjectVector[i].TheCord);
		Draw();
		i++;

	}

}
void WriteText::Draw()
{

	glPushMatrix();
	//int i =0;
	//changed int to size_t to avoid c4018 error 
	//http://stackoverflow.com/questions/8188401/c-warning-c4018-signed-unsigned-mismatch
	std::size_t i =0;
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_LIGHTING);
	//glDisable(GL_DEPTH_TEST);
	//glEnable(GL_COLOR_MATERIAL);
	
	//glLoadIdentity();
	// glOrtho(0, 800, 0, 600, -5, 5);
	// glMatrixMode(GL_MODELVIEW);
	glColor4f(m_colour.X, m_colour.Y, m_colour.Z,m_alpha);

	glRasterPos3f(m_cord.X,m_cord.Y,m_cord.Z);
	while (i < m_text.size())
	{
		//glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, m_text[i]);
		glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,m_text[i]);
		i++;	
	}

	//glDisable(GL_COLOR_MATERIAL);
	// glMatrixMode(GL_PROJECTION);
	//glEnable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_LIGHTING);
	
	glPopMatrix();
}

/*
void WriteText::PrintText(float TextX, float TextY, float TextZ, const std::string& text)
{
glPushMatrix();
int i = 0;
glRasterPos3f(TextX, TextY, TextZ);
while(i< text.size())
{
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, text[i]);
i++;	
}
glPopMatrix();
}
*/